package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.TaskLogProxy;
	import vn.demand.dragon.view.ProjectNavigatorMediator;
	import vn.demand.dragon.view.TaskLogScreenMediator;
	import vn.demand.dragon.view.components.TaskLogScreen;
	
	public class OpenProjectTaskLogsCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			var projectVO:Object = note.getBody();
			if (projectVO == null) {
				projectVO = {project_id: '', project_iso_code: '', project_company:'', project_shipping_type: '', project_date: '', project_start_date: ''};
			}
			var taskMediatorId:String = TaskLogScreenMediator.makeId(projectVO, true);
			RIALogger.debug(this, "tasklogMediatorId: " + taskMediatorId);
			if (facade.hasMediator(taskMediatorId)) {
				TabManager.openTab(TaskLogScreen, taskMediatorId);
				return;
			}
            facade.registerProxy(new TaskLogProxy(TaskLogProxy.NAME, projectVO));
			
			var ui:TaskLogScreen = TabManager.openTab(TaskLogScreen, taskMediatorId) as TaskLogScreen;
            facade.registerMediator(new TaskLogScreenMediator(projectVO, taskMediatorId, ui));
            
            facade.registerMediator(new ProjectNavigatorMediator(ProjectNavigatorMediator.NAME + "::" + taskMediatorId, ui.navigator, projectVO, TaskLogScreenMediator.NAME));
        }

	}
}